package com.hdaccp.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.hdaccp.dao.ShejishiDao;
import com.hdaccp.entity.Fuzeren;
import com.hdaccp.entity.Shejishi;
import com.hdaccp.util.BaseDao;

public class ShejishiDaoImpl extends BaseDao implements ShejishiDao {

	@Override
	public Shejishi getAll(int id) {
		String sql = "select * from `shejishi` where zid = ?";
		Object[] params = {id};
		ResultSet rs = super.executeQuery(sql, params);
		Shejishi s = null;
		try {
			if(rs.next()){
				s = new Shejishi();
				s.setId(rs.getInt("id"));
				s.setPhone(rs.getString("phone"));
				s.setName(rs.getString("name"));
				s.setZid(rs.getInt("zid"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(rs, rs.getStatement(),rs.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return s;
	}

	@Override
	public boolean update(Shejishi s) {
		String sql = "update `shejishi` set `name` = ?,`phone` = ? where zid = ?";
		Object[] params = {s.getName(),s.getPhone(),s.getZid()};
		boolean t = false;
		if(super.executeUpdate(sql, params)){
			String sql2 = "update `zong` set `dname` = ? where id = ?";
			Object[] params2 = {s.getName(),s.getZid()};
			if(super.executeUpdate(sql2, params2)){
				t = true;
			}
		}
		return t;
	}

}
